package cn.stylefeng.guns.modular.business.controller;

import cn.stylefeng.guns.modular.business.pojo.ResourceInfoRequest;
import cn.stylefeng.guns.modular.business.service.ResourceInfoService;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 控制器
 *
 * @author zhangyaowen
 * @date 2021/09/13 15:11
 */
@RestController
@ApiResource(name = "推荐模块控制器")
public class ResourceInfoController {

    @Resource
    private ResourceInfoService resourceInfoService;

    /**
     * 添加
     *
     * @author zhangyaowen
     * @date 2021/09/13 15:11
     */
    @PostResource(name = "添加", path = "/resourceInfo/add")
    public ResponseData add(@RequestBody @Validated(ResourceInfoRequest.add.class) ResourceInfoRequest resourceInfoRequest) {
        resourceInfoService.add(resourceInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author zhangyaowen
     * @date 2021/09/13 15:11
     */
    @PostResource(name = "删除", path = "/resourceInfo/delete")
    public ResponseData delete(@RequestBody @Validated(ResourceInfoRequest.delete.class) ResourceInfoRequest resourceInfoRequest) {
        resourceInfoService.del(resourceInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 编辑
     *
     * @author zhangyaowen
     * @date 2021/09/13 15:11
     */
    @PostResource(name = "编辑", path = "/resourceInfo/edit")
    public ResponseData edit(@RequestBody @Validated(ResourceInfoRequest.edit.class) ResourceInfoRequest resourceInfoRequest) {
        resourceInfoService.edit(resourceInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 查看详情
     *
     * @author zhangyaowen
     * @date 2021/09/13 15:11
     */
    @GetResource(name = "查看详情", path = "/resourceInfo/detail")
    public ResponseData detail(@Validated(ResourceInfoRequest.detail.class) ResourceInfoRequest resourceInfoRequest) {
        return new SuccessResponseData(resourceInfoService.detail(resourceInfoRequest));
    }

    /**
     * 获取列表
     *
     * @author zhangyaowen
     * @date 2021/09/13 15:11
     */
    @GetResource(name = "获取列表", path = "/resourceInfo/list")
    public ResponseData list(ResourceInfoRequest resourceInfoRequest) {
        return new SuccessResponseData(resourceInfoService.findList(resourceInfoRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author zhangyaowen
     * @date 2021/09/13 15:11
     */
    @GetResource(name = "分页查询", path = "/resourceInfo/page")
    public ResponseData page(String name) {
        ResourceInfoRequest resourceInfoRequest =  new ResourceInfoRequest();
        resourceInfoRequest.setResourceName(name);
        return new SuccessResponseData(resourceInfoService.findPage(resourceInfoRequest));
    }

    /**
     * 获取推荐列表
     *
     * @author zhangyaowen
     * @date 2021/09/13 15:11
     */
    @GetResource(name = "推荐资讯查询", path = "/resourceInfo/findTuiJian")
    public ResponseData findTuiJian() {
        return new SuccessResponseData(resourceInfoService.findTuiJian());
    }

    @GetResource(name = "资讯详情", path = "/resourceInfo/toReview")
    public ResponseData toReview(String id) {
        return new SuccessResponseData(resourceInfoService.toReview(id));
    }


}